<% layout('/layouts/default.html', {title: '考核任务指标表-指标信息管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${dcSupExamQuotaInfo}" action="${ctx}/quota/dcSupExamQuotaInfo/save" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('考核年度')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:hidden path="isNewRecord"/>
							<#form:hidden path="id" />
							<#form:select path="examYear" readonly="true" items="${yearList}" blankOption="true" data-placeholder="请选择" itemLabel="yearLabel" itemValue="yearValue" class="form-control width-120" defaultValue="${currentYear}"/>

							<#form:hidden path="quotaId" class="form-control"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('指标类别')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="quotaType" dictType="dc_quotaType_dan" blankOption="true"  data-placeholder="请选择" class="form-control required"  onchange="setQuotaClass()" defaultValue="${dcSupExamQuotaInfo.quotaType}"/>
						</div>
					</div>
				</div>
				<#form:hidden path="quotaClass"  defaultValue="1"/>
			</div>

			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('序号')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="sortNum" class="form-control digits" maxlength="4" placeholder="请输入数字" min="1"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('单位')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="quotaUnit" maxlength="255" class="form-control " placeholder="例：亿元、万元、个、条、家、项、户等;若无则不填"/>
						</div>
					</div>
				</div>

			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required ">*</span> ${text('指标名称')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:textarea path="quotaContent" rows="4" maxlength="255" class="form-control required" placeholder="例：政务公开"/>
						</div>
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required ">*</span> ${text('被考核单位')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:textarea path="exameOrgNames" rows="5" class="form-control required"   placeholder="请选择被考核单位" onclick="selectOrg()"/>
							<#form:hidden path="exameOrgs"/>
						</div>
					</div>
				</div>
			</div>

			<div class="col-xs-12">
				<div class="form-group">
					<label class="control-label col-sm-2" title="">
						<span class="required hide">*</span><i class="fa icon-question hide"></i></label>
					<div class="col-sm-10">

						<a onclick="fixGroup()"  class="btn btn-primary btn-sm mr10 mb10" style="background-color:#00B7EE;border-color: #00b7ee" >维护常用组</a>


						<a onclick="importGroup()"  class="btn btn-primary btn-sm mr10 mb10" style="background-color:#00B7EE;border-color: #00b7ee" >导入常用组</a>

					</div>
				</div>
			</div>

			<div class="row">

				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('权数')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="quotaWeight" class="form-control  required" max="150" maxlength="5" onkeyup="num(this)" placeholder="请输入数字"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('本年度目标')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="currentYaerGoal" maxlength="255" class="form-control required" placeholder="例：完成"/>
						</div>
					</div>
				</div>
			</div>


			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('考核方式')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="assessMethod" dictType="dc_exam_assessment" blankOption="true"  data-placeholder="请选择" class="form-control required" />
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('上一年度目标任务')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="lastYaerGoal" maxlength="255" class="form-control " placeholder="例：完成、量化任务数；"/>
						</div>
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('上一年度完成情况')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="lastYearComplete" maxlength="255" class="form-control " placeholder="定性指标填写“完成”；定量指标填写：量化任务数；"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="remarks" dictType="dc_exam_remarks" blankOption="true"  data-placeholder="请选择" class="form-control required" />
						</div>
					</div>
				</div>
			</div>


		</div>


		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-5 col-sm-10">
					<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('提 交')}</button>&nbsp;
					<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
				</div>
			</div>
		</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		var b;
		if($("#quotaType").val()=='14'){
			if($("#id").val()){
				if($("#quotaWeight").val()>3){
					js.showMessage("加分项权数超过3");
					return;
				}
			}else{
			js.ajaxSubmit({
				url:"${ctx}/quota/dcSupExamQuotaInfo/validationOrg",
				data:{"quotaId":$("#quotaId").val(),"quotaWeight":$("#quotaWeight").val(),"exameOrgs":$("#exameOrgs").val(),"quotaType":"14"},
				dataType: 'json',
				async:false,
				callback:function (data){
					if (data.result=="false"){
						js.showMessage(data.message);
						b="false";
					}else {
						b="true";
					}
				}
			})
			}
		}
		if(b=="false"){
			return;
		}
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
function setQuotaClass(){
	var quotaType =$("#quotaType").val();
	if(quotaType=='11'){
		$("#quotaWeight").removeAttr("max","3");
		$("#quotaClass").val(1)
	}
	if(quotaType=='13'){
		$("#quotaWeight").removeAttr("max","3");
		$("#quotaClass").val(3)
	}
	if(quotaType=='14'){
		$("#quotaWeight").attr("max","3");
		$("#quotaClass").val(2)
	}
}
function selectOrg(){
	layer.open({
		type: 2,
		title: ['选择机构'],
		area: ['850px', '600px'],
		content: "${ctx}/notice/dcSupExamNotice/getSixTeenFiveOrg?ids="+$("#exameOrgs").val()+"&param=${dcSupExamQuotaInfo.exameOrg}",
		success:function (layero,index){
			var iframe = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
			//iframe.child($("#noticeOrgs").val(),$("#noticeOrgNames").val());
		}
	});
}

function fixGroup(){
	js.layer.open({
		type: 2,
		title: ['维护常用组', 'font-size:18px; color:orange;'],
		area: ['800px', '500px'],
		scrollbar: true,
		shadeClose: false,
		content: "${ctx}/exam/dcSupExamSumScoreResult/examGroupList",
		btn1: function (index, layero) {
		},
		end:function () {

		}
	});
}

function importGroup(){
	var radioHtml='';
	$.ajax({
		url: "${ctx}/exam/dcSupExamSumScoreResult/listGroup",
		type: "get",
		cache: false,
		async:false,
		success: function(data){
			$.each(data,function(index,item){
				// log(item)
				radioHtml= radioHtml+'<div class="dbd"><input type="radio" name="groupId" value="'+item.id+'"/><span class="xbd">'+item.groupName+'</span></div> '
			})
			layer.open({
				type: 1
				,title: ['导入常用组', 'font-size:18px; color:orange;'] //不显示标题栏
				,btn: ['确认', '取消']
				,btnAlign: 'c'
				,area: '500px;'
				,moveType: 1 //拖拽模式，0或者1
				,content: radioHtml
				,yes: function(layero){
					$.ajax({
						url: "${ctx}/exam/dcSupExamSumScoreResult/radio",
						type: "post",
						cache: false,
						async:false,
						data: {
							"groupId":$("[name='groupId']").filter(":checked").val()

						},
						success: function(data){
							$("#exameOrgs").val(data.unitCodes)
							$("#exameOrgNames").val(data.unitNames)
						}
					});


				}
			});
		}
	});


}

$(function (){
	var flag =`${dcSupExamQuotaInfo.flag}`
	if(flag.length>0){
		if(quotaType=='11'){
			$("#quotaWeight").removeAttr("max","3");
			$("#quotaClass").val(1)
		}
		if(quotaType=='13'){
			$("#quotaWeight").removeAttr("max","3");
			$("#quotaClass").val(3)
		}
		if(quotaType=='14'){
			$("#quotaWeight").attr("max","3");
			$("#quotaClass").val(2)
		}
		$("#quotaType").attr("disabled","disabled");
	}
});

//强制最多输入2位小数
function num(obj){
	obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
	obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
}
</script>
<style>
	.dbd{
		padding: 10px;
		border-bottom: 1px solid gray;
		border-right: 1px solid gray;
		border-left: 1px solid gray;
		margin: auto 10px;
	}
	.dbd:nth-child(1){
		padding: 10px;
		border-bottom: 1px solid gray;
		border-top: 1px solid gray;
	}

	.xbd{
		margin-left: 10px;
	}
</style>